package com.DeliveryProgram.www.dao;

import com.DeliveryProgram.www.po.Business;
import com.DeliveryProgram.www.po.User;
import com.DeliveryProgram.www.util.JDBCutil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**用户交互产生的数据改变*/
public class RecationChange {
    private static Connection conn=null;
    private static Statement stmt=null;
    private static ResultSet rs=null;
    private static String sql=null;

    /**获取新得到的折扣*/
    public static void addHasCoupons(User us){
        try {
            conn= JDBCutil.getConnection();
            sql="INSERT INTO hascoupons(USER,coupons) VALUES("+us.getUid()+","+us.getCoupons().get(us.getCoupons().size()-1).getId()+")";
            stmt=conn.createStatement();
            stmt.execute(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCutil.close(stmt,conn);
        }
    }

    /**修改剩余折扣数量*/
    public static void updateMount(Business bu){
        try {
            conn= JDBCutil.getConnection();
            sql="UPDATE coupons SET mount="+bu.getCoupons().get(0).getMount()+" WHERE id="+bu.getCoupons().get(0).getId();
            stmt=conn.createStatement();
            stmt.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCutil.close(stmt,conn);
        }
    }
}
